# Definition for singly-linked list.
# class ListNode:
#     def __init__(self, val=0, next=None):
#         self.val = val
#         self.next = next
class Solution:
    def oddEvenList(self, head: ListNode) -> ListNode:
        if not head or not head.next:
            return head
        oddtemp=head
        even=eventemp=head.next
        temp=head.next.next
        while temp:
            oddtemp.next=temp
            oddtemp=oddtemp.next
            temp=temp.next
            if not temp:
                break
            eventemp.next=temp
            eventemp=eventemp.next
            temp=temp.next
        eventemp.next=None
        oddtemp.next=even
        return head

'''
执行用时：
56 ms
, 在所有 Python3 提交中击败了
64.14%
的用户
内存消耗：
15.3 MB
, 在所有 Python3 提交中击败了
59.14%
的用户
'''